Skip to content

Merge NeverType pre-scan into existing flattening loop#5374

Merged
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom
SanderMuller:perf/merge-never-scan
Apr 1, 2026
Merged

Merge NeverType pre-scan into existing flattening loop#5374
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom
SanderMuller:perf/merge-never-scan

Conversation

@SanderMuller
Copy link
Copy Markdown
Contributor

@SanderMuller SanderMuller commented Apr 1, 2026

Follow-up to #5325 and fe1df1a.

The N>2 pre-scan and the flattening loop both iterate all types checking for MixedType and NeverType. This removes the pre-scan and counts NeverTypes during the existing flattening loop instead. After the loop, a single bulk filter removes them all, replacing the per-element array_splice that was there before.

The $hasUnionOrBenevolent guard is no longer needed. UnionTypes get flattened first, then the post-loop filter removes any NeverTypes from the result.

The escaped mutant on !$types[0]->isArray()->yes() vs $types[0]->isArray()->no() is pre-existing — that line is unchanged from before this PR.

@SanderMuller SanderMuller marked this pull request as draft April 1, 2026 15:50
@SanderMuller SanderMuller force-pushed the perf/merge-never-scan branch 4 times, most recently from eec4924 to 258ec73 Compare April 1, 2026 19:10
Merge the separate NeverType pre-scan into the existing flattening
loop, eliminating the redundant iteration over all types.

Also skip the classification loop and inline the dedup for the common
case of 2 non-scalar, non-array, non-enum types.
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit ba4c9e4 into phpstan:2.1.x Apr 1, 2026
652 of 655 checks passed
@ondrejmirtes
Copy link
Copy Markdown
Member

It’s nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants